import {
  ActionType,
  PageContainer,
  ProColumns,
  ProTable,
} from '@ant-design/pro-components';
import services from '@/services/demo';
import React, { useRef } from 'react';
import { Button } from 'antd';
import { URL_PREFIX } from '@/constants';

const { queryListCollection } =
  services.ScoreController;


function GradePage() {
  const actionRef = useRef<ActionType>();
  const columns: ProColumns<API.ScoreType>[] = [
    {
      title: '学号',
      width: 100,
      dataIndex: 'sStuid',
      hideInForm: true,
    },
    {
      title: '姓名',
      width: 70,
      dataIndex: 'sStuname',
      valueType: 'text',
    },
    {
      title: '性别',
      width: 70,
      hideInSearch: true,
      dataIndex: 'sStusex',
      render(_, record) {
        if (record.sStusex === '0')
          return <span>男</span>
        else if (record.sStusex === '1')
          return <span>女</span>
        return ''
      }
    },
    {
      title: '学院',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sStucollege',
      valueType: 'text',
    },
    {
      title: '年级',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sStugrade',
      valueType: 'text',
    },
    {
      title: '专业',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sStuprofession',
      valueType: 'text',
    },
    {
      title: '班级',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sStuclass',
      valueType: 'text',
    },
    {
      title: '博雅读书 2场以上沙龙',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sBydsDssl',
      valueType: 'text',
    },
    {
      title: '博雅读书 1场以上报告会',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sBydsSpbgh',
      valueType: 'text',
    },
    {
      title: '博雅实践 志愿者',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sBysjZyzfw',
      valueType: 'text',
    },
    {
      title: '博雅实践 社会实践（1次以上）',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sBysjShsj',
      valueType: 'text',
    },
    {
      title: '博雅讲坛',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sByjt',
      valueType: 'text',
    },
    {
      title: '博雅修身',
      width: 100,
      hideInSearch: true,
      dataIndex: 'sByxs',
      valueType: 'text',
    },
  ];

  return (
    <PageContainer
      header={{
        title: '模块成绩汇总',
      }}
    >
      <ProTable<API.ScoreType>
        headerTitle="请输入完整的学号或姓名进行查询"
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        toolBarRender={() => [
          <Button key="2" type="primary">
            <a href={URL_PREFIX + '/score/excel'} target="_blank">导出Excel</a>
          </Button>
        ]}
        request={queryListCollection}
        columns={columns}
      />
    </PageContainer>
  );
}


export default GradePage;